package me.send.data.service.provider;

import java.util.Map;

import me.send.business.base.Pager;

public class BrokerEvaluateProvider {

	public String list(Map<String, Object> param) {
    	String sql = "select e.point,e.evaluate_id,e.orderid,e.userid,e.createtime,e.content,u.telephone as user_telephone,p.telephone as broker_telephone,p.username,u.nickname "
    			+ " from ((broker_evaluate e LEFT JOIN `user` u on u.userid=e.userid)"
    			+ " LEFT JOIN orders o on o.orderid = e.orderid) "
    			+ " LEFT JOIN popuser p on p.popid=o.brokerid where 1=1 ";
    	if (param != null) {
    		String broker_phone = (String) param.get("broker_phone");
    		String user_phone = (String) param.get("user_phone");
    		String start=(String) param.get("start");
    		String end=(String) param.get("end");
    		Pager page=(Pager) param.get("page");
    		if (broker_phone!=null&&!broker_phone.equals("")) {
    			sql += " and p.telephone=" + broker_phone;
    		}
    		if (user_phone!=null&&!user_phone.equals("")) {
    			sql += " and u.telephone=" + user_phone;
    		}
    		if(start!=null&&!start.equals("")){
    			sql+=" and e.createtime>='"+start+"'";
    		}
    		if(end!=null&&!end.equals("")){
    			sql+=" and e.createtime<'"+end+"'";
    		}
    		sql += " limit " + page.getStart() + "," + page.getRows();
    	}
    	return sql;
    }
	public String count(Map<String, Object> param) {
		String sql = "select count(1) "
				+ " from ((broker_evaluate e LEFT JOIN `user` u on u.userid=e.userid)"
				+ " LEFT JOIN orders o on o.orderid = e.orderid) "
				+ " LEFT JOIN popuser p on p.popid=o.brokerid where 1=1 ";
		if (param != null) {
			String broker_phone = (String) param.get("broker_phone");
			String user_phone = (String) param.get("user_phone");
			String start=(String) param.get("start");
			String end=(String) param.get("end");
			if (broker_phone!=null&&!broker_phone.equals("")) {
				sql += " and p.telephone=" + broker_phone;
			}
			if (user_phone!=null&&!user_phone.equals("")) {
				sql += " and u.telephone=" + user_phone;
			}
			if(start!=null&&!start.equals("")){
				sql+=" and e.createtime>='"+start+"'";
			}
			if(end!=null&&!end.equals("")){
				sql+=" and e.createtime<'"+end+"'";
			}
		}
		return sql;
	}
	
	
	
    
    
    
	
}
